from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class MyForm(models.Model) :
    user = models.ForeignKey(User)
    title = models.CharField(maxlength=1000)

    def __str__(self):
        return self.title

    class Admin:
        pass


class Question(models.Model) :
    myform = models.ForeignKey(MyForm)
    text = models.CharField(maxlength=9000)

    def __str__(self):
        return self.text

    class Admin:
        pass


class Answer(models.Model) :
    question = models.ForeignKey(Question)
    text = models.CharField(maxlength=9000)
    valor = models.BooleanField()

    def __str__(self):
        return self.text

    class Admin:
        pass

class Stats(models.Model) :
    user = models.ForeignKey(User)
    myform = models.ForeignKey(MyForm)
    questions_total = models.IntegerField()
    questions_correct = models.IntegerField()
    date = models.DateTimeField(auto_now=True)

    def __str__(self):
        average = (self.questions_correct*100)/self.questions_total
        return str(average)

